package org.study.opensearch.boot.service;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.study.opensearch.boot.model.Product;
import org.study.opensearch.boot.repository.ProductRepository;

import java.math.BigDecimal;

/**
 * 作用描述
 *
 * @author doveylovey
 * @version v1.0.0
 * @email 1135782208@qq.com
 * @date 2025年05月09日
 */
@Slf4j
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Service
public class ProductInitializer implements InitializingBean {
    private final ProductRepository productRepository;

    @Override
    public void afterPropertiesSet() throws Exception {
        productRepository.save(
                Product.builder()
                        .id("1")
                        .name("Utopia Bedding Bed Pillows")
                        .price(new BigDecimal(39.99))
                        .quantity(2)
                        .description("These professionally finished pillows, with high thread counts, provide great comfort against your skin along with added durability that easily resists wear and tear to ensure a finished look for your bedroom.")
                        .vendor("Utopia Bedding")
                        .build()
        );
        productRepository.save(Product.builder()
                .id("2")
                .name("Echo Dot Smart speaker")
                .price(new BigDecimal(34.99))
                .quantity(10)
                .description("Our most popular smart speaker with a fabric design. It is our most compact smart speaker that fits perfectly into small spaces.")
                .vendor("Amazon")
                .build()
        );
    }
}
